package com.ll.beautymall.ui.home.taobaoproduct;

import android.content.ContentValues;
import android.content.Intent;
import android.graphics.Paint;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.ll.beautymall.R;
import com.ll.beautymall.base.BaseActivity;
import com.ll.beautymall.bean.ObjectProduct;
import com.ll.beautymall.db.ProductDao;
import com.squareup.picasso.Picasso;

import butterknife.BindView;
import butterknife.OnClick;

public class TaoBaoProductActivity extends BaseActivity {

    @BindView(R.id.iv_category_detail_back)
    ImageView ivCategoryDetailBack;
    @BindView(R.id.tv_category_detail_title)
    TextView tvCategoryDetailTitle;

    @BindView(R.id.iv_product_cover)
    ImageView ivProductCover;
    @BindView(R.id.tv_sale_price)
    TextView tvSalePrice;
    @BindView(R.id.tv_old_price)
    TextView tvOldPrice;
    @BindView(R.id.tv_discount)
    TextView tvDiscount;
    @BindView(R.id.tv_product_title)
    TextView tvProductTitle;
    @BindView(R.id.lv_product_imgs)
    ListView lvProductImgs;

    private ObjectProduct product;
    private ProductDao productDao;

    @Override
    public int getLayoutId() {
        return R.layout.activity_tao_bao_product;
    }

    @Override
    public void initView() {
        Intent intent = getIntent();
        product = (ObjectProduct) intent.getSerializableExtra("product");
        tvCategoryDetailTitle.setText(product.getTaobao_title());
        setData();
        productDao = new ProductDao(this);
    }

    private void setData() {
        tvProductTitle.setText(product.getTaobao_title());
        tvSalePrice.setText("￥" + product.getTaobao_promo_price());
        tvOldPrice.setPaintFlags(tvOldPrice.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        tvOldPrice.setText("￥" + product.getTaobao_price());
        tvDiscount.setText(product.getDiscount());
        Picasso.with(this).load(product.getTaobao_pic_url()).into(ivProductCover);
    }


    @OnClick({R.id.iv_category_detail_back, R.id.rb_like, R.id.bt_addto_cart, R.id.bt_buy})
    public void onClick(View view) {
        switch (view.getId()) {
                 case R.id.iv_category_detail_back:
                finish();
                break;
            case R.id.rb_like:
                Toast.makeText(TaoBaoProductActivity.this, "collect", Toast.LENGTH_SHORT).show();
                break;
            case R.id.bt_addto_cart:
                Toast.makeText(TaoBaoProductActivity.this, "cart", Toast.LENGTH_SHORT).show();
                ContentValues values = new ContentValues();
//                values.put("");
                productDao.insert("cart", values);
                break;
            case R.id.bt_buy:
                Toast.makeText(TaoBaoProductActivity.this, "buy", Toast.LENGTH_SHORT).show();
                break;
        }
    }

}
